package org.infosys.hello04;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
* @Description: 单项发送
* @Author: hank
* @Version: 1.0
* @Date:  2022/7/27 1:47
*/
public class Producer {

    public static void main(String[] args) throws Exception {
        // 1.创建消费者对象
        DefaultMQProducer producer = new DefaultMQProducer("hello_producer_group");
        // 2.连接mq
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 3.启动消费者
        producer.start();
        // 4.单向发送
        Message message = new Message("hello_topic", "hello_tags2", "我在源码学Java！".getBytes(StandardCharsets.UTF_8));
        producer.send(message);
    }
}
